﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using IntraVision.Xml;
using System.Web;

namespace IntraVision.Web
{
    /// <summary>
    /// Общие настройки приложения
    /// </summary>
    public class Settings
    {
        public static Dictionary<string, string> DBSettings
        {
            get { return HttpContext.Current.Application["dbsettings"] as Dictionary<string, string>; }
        }

        /// <summary>
        /// Получить настройку из БД
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetFromDatabase(string key)
        {
            HttpContext context = HttpContext.Current;
            if (context != null && context.Application["dbsettings"] != null)
            {
                Dictionary<string, string> settings = context.Application["dbsettings"] as Dictionary<string, string>;
                if (settings != null && settings.ContainsKey(key))
                    return settings[key];
                else
                    return "";
            }
            else
                return "";
        }

        /// <summary>
        /// Получить настройку из web.config
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetFromWebConfig(string key)
        {
            HttpContext context = HttpContext.Current;
            if (context != null && context.Application["configsettings"] != null)
            {
                Dictionary<string, string> settings = context.Application["configsettings"] as Dictionary<string, string>;
                if (settings != null && settings.ContainsKey(key))
                    return settings[key];
                else
                    return "";
            }
            else
                return "";
        }
    }
}
